// cimgwrapper.h

#pragma once
#include "gditobitmap.h"
using namespace System;
using namespace System::Drawing;
using namespace System::Drawing::Imaging;
using namespace System::Runtime::InteropServices;
using namespace cimg_library;
using namespace convertor;
namespace ManagedCIMG   //main wrapper node. here you can add your method declaration that u need to access in dot net
{  
	public ref class ManagedCImg
	{
	private:
		GDItoCImgConv^ conv;
		CImg<float> *img;
		Bitmap^ bmglob;
	public:
		ManagedCImg();
		ManagedCImg(Bitmap^ bm);
		~ManagedCImg();
		Bitmap^ ToBitmap();
		void ToGray(float Value,bool soft_thresold,bool strict_threshold);
		void Blur(float sigma,bool boundarycondition,bool is_gaussian);
		void DrawText(int x,int y,String ^text,int color[]);
		void Display();
		int getCImgVersion();
		property Bitmap^ BitmapImage{
			void set(Bitmap^ referenced){
				bmglob=referenced;
				img=new CImg<float>;
				conv->FillCImgFromBitmap(*img,bmglob);
			};
			Bitmap^ get(){
				return bmglob;
			}
		}		
	};
	ManagedCImg::ManagedCImg(){

	}
	ManagedCImg::ManagedCImg( Bitmap^ bm )
	{
		img = new CImg<float>;  //this was the problem and now it woks great(forgetting allocating memory)
		System::Drawing::Rectangle rc=System::Drawing::Rectangle(0,0,bm->Width,bm->Height);
		Bitmap^ bmnew = bm->Clone(rc,PixelFormat::Format32bppArgb);
		conv->FillCImgFromBitmap(*img,bmnew);
	}
	enum CImgColor:int
	{
		one=1  //TODO:error when trying to assign an array
	};
}